home *** CD-ROM | disk | FTP | other *** search
- Path: news.microsoft.com!news
- From: a-cnadc@microsoft.com (Dann Corbit)
- Newsgroups: comp.lang.c
- Subject: Re: Do you have ever pass structures?
- Date: 23 Feb 1996 01:32:56 GMT
- Organization: Microsoft Corporation
- Message-ID: <4gj5g8$6d2@news.microsoft.com>
- References: <4ge8mi$qjm@srvr1.engin.umich.edu> <312BE9C9.67A2284E@eden.com> <4gie7s$jim@hacgate2.hac.com>
- NNTP-Posting-Host: 157.57.171.202
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.14
-
- In article <4gie7s$jim@hacgate2.hac.com>, collins@thor.tu.hac.com says...
- >
- >Shane Sadler (nexus@eden.com) wrote:
- >
- >: As you know passing an entire structure to a function pushes that
- >: structure onto the stack. By passing pointers, you avoid that sort of
- >: overhead and your code is more efficient. When I'm writing what Mr.
- >: Collins would call "disposable programs," I might just declare my
- > ^^^^^^^
- >
- >Sounds like an intelligent, rational, good-looking chap.
- >
- >: structures globally just out of laziness and expediency, but I can't
- >: think of a case in which I would pass the whole structure. So my answer
- >: would be "no". Of course, someone else may have experience with passing
- >: very small structures (one or two elements). There might be some
- >: advantage in this, but a "REAL" advantage? I doubt it. Depends on what
- >: you mean by "REAL," I guess...
- >
- >: -- Shane
- >
- >
- >About the only use I can come up with for passing a large structure on the
- >stack would be to interface to a routine written in another language.
- >Exactly what that language would be, I haven't a clue. Outside of this,
- >the pass-by-value mechanism for a large structure seems like one of those
- >interesting little tidbits that is nice to know about, but rarely ever
- >used.
- >
- >Anyone have any examples of using this, where it actually saved time or
- >effort over passing a pointer?
- >
- >
- > -- Collins --
- >
- >-----
- >The views expressed here are mine alone.
- >
- >Ron Collins/Hughes Aircraft Company/M20,P20/Tucson Az 85706
- >rcollins@thor.tu.hac.com collins@seagull.rtd.com
- >ยก----
- The reason to pass a struct by value is to preserve the contents,
- just like any other variable. Obviously, a recursive routine with
- large structures passed by value would be a disaster, but structures
- of small size are not a problem. Even a large structure might be
- passed if not called iteratively. Imagine a sorting routine where
- we have a struct that contains an array of pointers to records.
- We could give an instance of this struct to several competing
- methods which have an internal "race" to see who gets done first.
- We don't want to pass the array address, because the sorts would
- write overtop of each other. It depends on the architecture too.
- In an old DOS app, with a 64K stack, passing structures by value
- would be foolhardy. But Windows NT starts with a 1 Meg stack and
- grows it as needed. I admit that I rarely use this feature, but
- once in a great while it is useful.
- --
- The opinions expressed in this message are my own personal views
- and do not reflect the official views of Microsoft Corporation.
-
-